/*
 * @Author: Leo.wang wanglizhigs@163.com
 * @Date: 2024-09-02 22:42:44
 * @LastEditors: Leo.wang wanglizhigs@163.com
 * @LastEditTime: 2024-09-03 22:50:05
 * @FilePath: /metaverse-manage/app/service/Contact.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { Service } from 'egg';

export default class ContactService extends Service {
  // 查找所有
  async queryAllContacts() {
    const result = await this.app.mysql.query('select id,name,phone,address,description,rqcode,active from sys_contact');
    return result;
  }

  async queryContactById(id: number) {
    const result = await this.app.mysql.query(`select id,name,phone,address,description,rqcode,active from sys_contact where id = '${id}'`);
    return result[0];
  }

  async createContact(contact) {
    const result = await this.app.mysql.insert('sys_contact', contact);
    return result;
  }

  async updateContact(id, contact) {
    const result = await this.app.mysql.update('sys_contact', contact, {
      where: { id },
    });
    return result;
  }
  async removeContact(id: number) {
    const result = await this.app.mysql.delete('sys_contact', { id });
    return result;
  }
}
